<template>
	<div class="system-role-container layout-padding">
		<div class="system-role-padding layout-padding-auto">
			<el-card shadow="hover" class="pageQueryBoxArea mb10">
				<el-form :model="state.param" :inline="true">
					<el-form-item label="门店类型：">
						<el-select v-model="state.param.source" placeholder="请选择门店类型">
							<el-option v-for="item in state.query.storeType" :key="item.value" :label="item.label"
								:value="item.value" />
						</el-select>
					</el-form-item>
					<el-form-item label="门店状态：">
						<el-select v-model="state.param.storeStatus" placeholder="请选择门店状态">
							<el-option v-for="item in state.query.storeStatus" :key="item.value" :label="item.label"
								:value="item.value" />
						</el-select>
					</el-form-item>
					<el-form-item label="选择门店：">
						<el-select v-model="state.param.nodeId" placeholder="请选择门店">
							<el-option v-for="item in state.query.storeList" :key="item.id" :label="item.name"
								:value="item.id" />
						</el-select>
					</el-form-item>
					<el-form-item label="成本方式：">
						<el-select v-model="state.param.nodeId" placeholder="请选择成本方式">
							<el-option v-for="item in state.query.costMethod" :key="item.value" :label="item.label"
								:value="item.value" />
						</el-select>
					</el-form-item>
					<el-form-item label="选择日期：">
						<el-date-picker v-model="state.param.dateTime" type="daterange" unlink-panels :shortcuts="shortcuts"
							format="YYYY/MM/DD" value-format="YYYY-MM-DD" range-separator="-" :disabled-date="disabledDate"
							start-placeholder="开始日期" end-placeholder="结束日期" />
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="search()">
							<el-icon>
								<ele-Search />
							</el-icon> 搜 索
						</el-button>
						<el-button type="primary" @click="search()">
							<el-icon>
								<ele-Refresh />
							</el-icon> 重 置
						</el-button>
					</el-form-item>
				</el-form>
			</el-card>
			<el-card shadow="hover" v-loading="state.loading" style="display: flex;flex-direction: column;flex: 1;height: inherit;">
				<section style="flex: 1;display: flex;flex-direction: column; flex: 1;height: inherit;">
					<el-table :data="state.tableData" v-loading="state.loading">
						<el-table-column label="ID" prop="name" width="90" />
						<el-table-column label="门店" prop="cardItemName" />
						<el-table-column label="类型" prop="cardItemName" />
						<el-table-column label="状态" prop="cardItemName" />
						<el-table-column label="综合业绩" prop="cardItemName" />
						<el-table-column label="利润" prop="cellPrice" />
						<el-table-column prop="coverRatio" width="120">
							<template #header>
								<section style="display: flex; align-items: center;">
									<span>利润率</span>
									<el-tooltip effect="dark" content="利润率 = 利润 / (销售收入 + 充值收入 + 还款收入)" style=""
										placement="right-start">
										<svg t="1702367275758" style="transform: translateY(2px);" class="icon"
											viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2391"
											width="18" height="18">
											<path
												d="M512 64C264.8 64 64 264.8 64 512s200.8 448 448 448 448-200.8 448-448S759.2 64 512 64z m32 704h-64v-64h64v64z m11.2-203.2l-5.6 4.8c-3.2 2.4-5.6 8-5.6 12.8v58.4h-64v-58.4c0-24.8 11.2-48 29.6-63.2l5.6-4.8c56-44.8 83.2-68 83.2-108C598.4 358.4 560 320 512 320c-49.6 0-86.4 36.8-86.4 86.4h-64C361.6 322.4 428 256 512 256c83.2 0 150.4 67.2 150.4 150.4 0 72.8-49.6 112.8-107.2 158.4z"
												p-id="2392" fill="#bfbfbf"></path>
										</svg>
									</el-tooltip>
								</section>
							</template>
						</el-table-column>
						<el-table-column label="销售收入" prop="orderPrice" />
						<el-table-column label="充值收入" prop="cellPrice" />
						<el-table-column label="还款收入" prop="buyCount" />
						<el-table-column label="产品成本" prop="buyCount" />
						<el-table-column label="人员成本" prop="buyCount" />
						<el-table-column label="门店开支" prop="buyCount" />
						<el-table-column label="手续费" prop="buyCount" />
						<!-- <el-table-column prop="coverRatio" width="120">
							<template #header>
								<section style="display: flex; align-items: center;">
									<span>退款</span>
									<el-tooltip  effect="dark" content="此处只计算退款至银行卡或现金的金额"  style=""
										placement="right-start" >
										<svg t="1702367275758" style="transform: translateY(2px);" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2391" width="18" height="18"><path d="M512 64C264.8 64 64 264.8 64 512s200.8 448 448 448 448-200.8 448-448S759.2 64 512 64z m32 704h-64v-64h64v64z m11.2-203.2l-5.6 4.8c-3.2 2.4-5.6 8-5.6 12.8v58.4h-64v-58.4c0-24.8 11.2-48 29.6-63.2l5.6-4.8c56-44.8 83.2-68 83.2-108C598.4 358.4 560 320 512 320c-49.6 0-86.4 36.8-86.4 86.4h-64C361.6 322.4 428 256 512 256c83.2 0 150.4 67.2 150.4 150.4 0 72.8-49.6 112.8-107.2 158.4z" p-id="2392" fill="#bfbfbf"></path></svg>
									</el-tooltip> 
								</section> 
							</template>
						</el-table-column> -->
					</el-table>
					<el-row justify="end">
						<el-col :span="24" class="flex-end-center">
							<el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange"
								class="mt15" :pager-count="5" :page-sizes="[10, 20, 30,50,100,500,1000]"
								v-model:current-page="state.param.pageNum" background v-model:page-size="state.param.pageSize"
								layout="total, sizes, prev, pager, next, jumper" :total="state.total">
							</el-pagination>
						</el-col>
					</el-row>
				</section>
			</el-card>
		</div>
		<CardDialog v-model="cardDialogVisble" :statistics="state.param.statistics" :id="state.param.rowId" />
	</div>
</template>

<script setup lang="ts" name="funCountup">
import { onMounted, reactive, ref } from 'vue';

import CardDialog from '/@/views/analysis/profit/components/CardDialog.vue'
import { storeNodeList } from '/@/api/order';
const state = reactive({
	param: {
		type: 4,
		source: 0, // 0 门店 2 线上 //设置不了得值是哪个？
		mode: null, // 门店类型  null(默认) 全部 0 直营  1 加盟
		nodeId: null, // 门店id
		storeStatus: -1,
		// 销售渠道
		channel: null,
		status: null,
		// 支付方式
		dateTime: [],
		startTime: "",
		endTime: "",
		timeInterval: 3,
		total: 0,
		keyword: "",
		pageNum: 1,
		pageSize: 10,
		change: 999,
		storeType: null as null | number,
		statistics: 1,
		rowId: -1,
		store: ''
	},
	query: {
		storeType: [
			{ value: null, label: '全部' },
			{ value: 0, label: '直营' },
			{ value: 1, label: '加盟' }
		],
		storeStatus: [
			{ value: -1, label: '全部' },
			{ value: 1, label: '正常' },
			{ value: 2, label: '闭店' },
			{ value: 3, label: '休息' }
		],
		costMethod: [
			{ value: 1, label: '销售利润' },
			{ value: 1, label: '服务利润' },
		],
		storeList: [] as Array<any>,
	},
	loading: false,
	total: 0,
	tableData: [
		{
			id: 1,
			cardItemName: '测试',
			property: '属性名称',
			spec: '规格',
			salesVolume: '销量',
			cellPrice: '销售价格',
			orderPrice: '销售金额',
			buyCount: '购买人数',
			coverRatio: '客户覆盖率',
			performanceRatio: '业绩占比',
			allRatio: '全款率',
			startTime: '2023-12-22 12:36:54',
			endTime: '2023-12-22 12:36:54',
			status: '活动状态',
		}
	] as Array<any>

});

const shortcuts = [
	{
		text: '本月',
		value: () => {
			const end = new Date()
			const start = new Date()
			start.setTime(start.setDate(1))
			return [start, end]
		},
	},
	{
		text: '近一个月',
		value: () => {
			const end = new Date()
			const start = new Date()
			start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
			return [start, end]
		},
	},
	{
		text: '近三个月',
		value: () => {
			const end = new Date()
			const start = new Date()
			start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
			return [start, end]
		},
	},
	{
		text: '近半年',
		value: () => {
			const end = new Date()
			const start = new Date()
			start.setTime(start.getTime() - 3600 * 1000 * 24 * 180)
			return [start, end]
		},
	},
	{
		text: '近一年',
		value: () => {
			const end = new Date()
			const start = new Date()
			start.setTime(start.getTime() - 3600 * 1000 * 24 * 365)
			return [start, end]
		},
	},
]

const disabledDate = (time: Date) => time.getTime() > Date.now();

const cardDialogVisble = ref(false)
const defaultTime2: [Date, Date] = [
	new Date(2000, 1, 1, 12, 0, 0),
	new Date(2000, 2, 1, 8, 0, 0),
]

const search = () => { }

const handleSizeChange = () => { }
const handleCurrentChange = () => { }
const previewInfo = (id: number) => {
	state.param.rowId = id
	cardDialogVisble.value = true
}
/**
 * 获取门店列表
 * mode  null /全部   0直营  1加盟
 */
const getStoreNodeList = async () => {
	const { results } = await storeNodeList({ mode: null, current: 1, size: 50 });
	let no1 = [{ id: null, name: '全部' }]
	state.query.storeList = [...no1, ...results.records];
}


// 页面加载时
onMounted(() => {
	getStoreNodeList()
});
</script>


<style scoped lang="scss">
:deep(.el-card__body){
	display: flex;
	flex-direction: column;
	flex: 1;
	height: inherit;
	.el-table{
		flex: 1;
		.el-table__inner-wrapper::before{
			background: none !important;
		}
	}
}

</style>
